package com.gusto.engine.recommend.prediction;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.gusto.engine.colfil.Evaluation;
import com.gusto.engine.recommend.PredictionService;
import com.gusto.engine.recommend.prediction.base.BaseCollaborativeImpl;

/**
 * <p>Collaborative filtering algorithm considering 'item mean rating' as a default value.</p>
 * 
 * @see CollaborativeImpl
 * 
 * @author amokrane.belloui@gmail.com
 *
 */
public class Collaborative2Impl extends BaseCollaborativeImpl implements PredictionService {
	
	private Logger log = Logger.getLogger(getClass());
	
	protected Double doPrediction(List<? extends Evaluation> evals, double user_mean, double item_mean, Map<Long, Double> usersWeights, Map<Long, Double> itemsWeights) {
		Double val = null;
		
		// Calculate the mean evaluation for the Item (no neighborhood)
		if (evals.size() >= this.minEvals) {
			log.debug("Collaborative prediction");
			val = this.buildPrediction(evals, user_mean, item_mean, usersWeights, itemsWeights);
			//nb_pred ++;
		}
		else {
			log.debug("Item mean rating prediction");
			val = item_mean;
		}
		return val;
	}
	
}
